#ifndef MG_IIC_H
#define MG_IIC_H

#include "ite/itp.h" //for all ith driver (include GPIO) & MACRO
#include <sys/ioctl.h>
#include <unistd.h>

/********************Ä£ÄâI2CÅäÖÃ************************/
//I2C0 GPIO
//¸ºÔðLEDÇý¶¯Ð¾Æ¬ºÍEEPROMµÄ´æ´¢
#define I2C0_SDA_Pin	15
#define I2C0_SCL_Pin	16
#define I2C0_SDA_HIGH()	ithGpioSet(I2C0_SDA_Pin)
#define I2C0_SDA_LOW()	ithGpioClear(I2C0_SDA_Pin)
#define I2C0_SCL_HIGH()	ithGpioSet(I2C0_SCL_Pin)
#define I2C0_SCL_LOW()	ithGpioClear(I2C0_SCL_Pin)
#define I2C0_SDA_READ	ithGpioGet(I2C0_SDA_Pin)

//I2C1 GPIO
//¸ºÔðÐý×ª´«¸ÐÆ÷ºÍÊÖÊÆ´«¸ÐÆ÷µÄ¶ÁÐ´
#define I2C2_SDA_Pin	44
#define I2C2_SCL_Pin	45
#define I2C2_SDA_HIGH()	ithGpioSet(I2C2_SDA_Pin)
#define I2C2_SDA_LOW()	ithGpioClear(I2C2_SDA_Pin)
#define I2C2_SCL_HIGH()	ithGpioSet(I2C2_SCL_Pin)
#define I2C2_SCL_LOW()	ithGpioClear(I2C2_SCL_Pin)
#define I2C2_SDA_READ	ithGpioGet(I2C2_SDA_Pin)
//I2C0
void I2C0_GPIO_Init(void);
void I2C0_Start(void);
void I2C0_Stop(void);
uint8_t I2C0_Wait_Ack(void);
void I2C0_Ack(void);
void I2C0_NAck(void);
void I2C0_Send_Byte(uint8_t txd);
uint8_t I2C0_Read_Byte(uint8_t ack);
//I2C2
void I2C2_GPIO_Init(void);
void I2C2_Start(void);
void I2C2_Stop(void);
uint8_t I2C2_Wait_Ack(void);
void I2C2_Ack(void);
void I2C2_NAck(void);
void I2C2_Send_Byte(uint8_t txd);

//³õÊ¼»¯IIC0
void I2C0_Init(void);
//I2C0¶Á8Î»¼Ä´æÆ÷×Ö½Ú
uint8_t I2C0_Read_8Reg(uint8_t SlaveAddr, uint8_t regAddr);
//I2C0¶Á16Î»¼Ä´æÆ÷×Ö½Ú
uint8_t I2C0_Read_16Reg(uint8_t SlaveAddr, uint8_t regHAddr, uint8_t regLAddr);
//I2C0¶Á16Î»¼Ä´æÆ÷×Ö½Ú
void I2C0_Read_More_16Reg(uint8_t SlaveAddr, uint8_t regHAddr, uint8_t regLAddr, uint8_t* Data, uint32_t DataLen);
//I2C0写8位寄存器
uint32_t I2C0_Write_8Reg(uint8_t SlaveAddr, uint8_t RegAddr, uint8_t* Data, uint8_t DataLen);
//I2C0Ð´16Î»¼Ä´æÆ÷(×î´ó255³¤¶È)
void I2C0_Write_16Reg(uint8_t SlaveAddr, uint8_t RegHAddr, uint8_t RegLAddr, uint8_t* Data, uint16_t DataLen);

uint8_t I2C2_Read_Byte(uint8_t ack);
//I2C1¶Á¼Ä´æÆ÷×Ö½Ú
uint8_t I2C2_Read_Reg(uint8_t SlaveAddr, uint8_t regAddr);
//I2C1¶Á¶à¸ö×Ö½Ú
void I2C2_Read(uint8_t SlaveAddr, uint8_t regAddr, uint8_t DataLen, uint8_t* RecieveData);
//I2C1Ð´¼Ä´æÆ÷
void I2C2_Write_Reg(uint8_t SlaveAddr, uint8_t RegAddr, uint8_t* Data, uint8_t DataLen);

void Mg_I2C_Init(void);

#endif